package com.xfcy.blog.controller.system;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.RoleDTO;
import com.xfcy.blog.service.RoleService;
import com.xfcy.blog.valid.AddGroup;
import com.xfcy.blog.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统管理-角色表 (Role)表控制层
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:06
 */
@RestController
@RequestMapping("/system/role")
@Api(tags = "角色管理-接口")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation(value = "角色列表", httpMethod = "GET", response = R.class, notes = "角色列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @SaCheckLogin
    public R list(Integer pageNo, Integer pageSize, String name) {
        return roleService.listRole(pageNo, pageSize, name);
    }

    @OperationLogger(value = "添加角色")
    @ApiOperation(value = "添加角色", httpMethod = "POST", response = R.class, notes = "添加角色")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @SaCheckPermission("/system/role/create")
    public R create(@Validated(AddGroup.class) @RequestBody RoleDTO roleDTO) {
        return roleService.createRole(roleDTO);
    }

    @OperationLogger(value = "角色详情")
    @GetMapping("/queryRoleId")
    @SaCheckPermission("/system/role/queryRoleId")
    @ApiOperation(value = "角色详情", httpMethod = "GET", response = R.class, notes = "角色详情")
    public R queryRoleId(Integer roleId) {
        return roleService.queryRoleId(roleId);
    }

    @OperationLogger(value = "修改角色信息")
    @PostMapping("/update")
    @SaCheckPermission("/system/role/update")
    @ApiOperation(value = "修改角色信息", httpMethod = "GET", response = R.class, notes = "修改角色信息")
    public R update(@Validated(UpdateGroup.class) @RequestBody RoleDTO roleDTO) {
        return roleService.updateRole(roleDTO);
    }

    @OperationLogger(value = "批量删除或删除角色")
    @DeleteMapping("/remove")
    @SaCheckPermission("/system/role/remove")
    @ApiOperation(value = "批量删除或删除角色", httpMethod = "DELETE", response = R.class, notes = "批量删除或删除角色")
    public R remove(@RequestBody List<Integer> ids) {
        return roleService.removeRoles(ids);
    }


}

